<!--
* description: 验货通道-新增编辑弹窗
-->
<template>
  <section class="editCarBrand">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      width="400px"
      @close="sendCode"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :styleType="$store.state.app.dialogType"
      ></dialogHeader>
      <div class="filter-container filter-params">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire + comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :isMul="comp.isMul"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :dateOptionsType="comp.dateOptionsType"
          ></component>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{ comp.text }}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/wms/mixins/formMixins";
import { wmsApis } from "@/api/wms/baseData/api";
import request from "@/utils/request";
import storage from "@/utils/storage";
export default {
  // 组件混入对象
  mixins: [formMixins],
  components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: wmsApis.saveSuppUser,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.save(),
          text: "保存" //"保存"
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          clickEvent: () => this.reset(),
          text: "重置" //"重置"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "edit_compKey1",
          labelName: "用户编号",
          textField: "WAREHOUSE_USER_ID",
          codeField: "USER_ID",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsWarehouse"),
          type: "propus",
          isMust: true,
          span: 23,
          isMul: false,
          readonly: false,
          returnCodeField: "USER_ID",
          returnTextField: "WAREHOUSE_USER_ID",
          isRequire: true
        },
        {
          compKey: "edit_compKey2",
          labelName: "用户名称",
          span: 23,
          codeField: "EMP_NAME",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          disabled: true,
          isMust: true
        },
        {
          compKey: "edit_compKey3",
          labelName: "供应商",
          textField: "PARTNER_SHORT_NAME",
          codeField: "PARTNER_ID",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsSupplierTwo"),
          type: "propus",
          isMust: true,
          span: 23,
          isMul: false,
          isRequire: true,
          readonly: false,
          returnCodeField: "PARTNER_ID",
          returnTextField: "PARTNER_SHORT_NAME",
          isRequire: true
        },
        {
          compKey: "edit_compKey5",
          labelName: "启用状态",
          codeField: "IS_ENABLE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 23,
          options: [
            {
              label: "启用",
              value: "1"
            },
            {
              label: "禁用",
              value: "0"
            }
          ],
          isMust: true,
          isRequire: true
        }
      ],
      // 标题
      textMap: {
        edit: "编辑供应商用户管理",
        add: "新增供应商用户管理"
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        USER_ID: "",
        WAREHOUSE_USER_ID: "",
        EMP_NAME: "",
        PARTNER_ID: "",
        PARTNER_SHORT_NAME: "",
        IS_ENABLE: "1",
        SUPP_USER_ID: ""
      }
    };
  },
  methods: {
    //保存
    save() {
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        var saveObj = JSON.parse(JSON.stringify(this.formField));
        //保存表单
        this.saveForm(saveObj);
        storage.remove(this.$route.query.pageCode);
      }
    }
  }
};
</script>
<style type="text/css" scoped>
.filter-params .el-col label .curName {
  width: 150px;
}
</style>
